<?php 

class Profile{

	function getNotifications($steamID){
		$ret = array();
		$DB = new DB();
		$con = $DB->conDB();

		if($steamID > 0){
			$globalCount = 0;
			
			// Open Matches Notification
			$sql="Select m.MatchID, md.Submitted, (
													SELECT COUNT(mdcmv.SteamID) as CountCancelSubmitts
													FROM MatchDetailsCancelMatchVotes mdcmv
													WHERE SteamID = ".secureNumber($steamID)." AND mdcmv.MatchID = m.MatchID
													) as CountCancelSubmitts
					FROM `MatchDetails` md JOIN `Match` m ON md.MatchID = m.MatchID
			
					WHERE md.SteamID = ".secureNumber($steamID)." AND m.TeamWonID = -1 AND m.Canceled = 0
					";
				
// 			$sql="Select m.MatchID, md.Submitted, COUNT(mdcmv.SteamID) as CountCancelSubmitts
// 					FROM `MatchDetails` md JOIN `Match` m ON md.MatchID = m.MatchID
// 					LEFT JOIN MatchDetailsCancelMatchVotes mdcmv ON mdcmv.SteamID = md.SteamID AND mdcmv.MatchID = m.MatchID
// 					WHERE md.SteamID = ".secureNumber($steamID)." AND m.TeamWonID = -1 AND m.Canceled = 0
// 					";
			$ret['debug'] .= $sql;
			$data = $DB->multiSelect($sql);
			if($data[0]['MatchID'] != ""){
				$count = count($data);
			}
			else{
				$count = 0;	
			}
			if($count > 0){
				$tmpData['count'] = $count;
				$matchString = ($count > 1 ? 'Matches' : 'Match');
				$tmpData['message'] = "open ".$matchString;
				$tmpData['href'] = "openMatches.php";
				
				$retData[] = $tmpData;
				$globalCount++;
			}
			
			// Submissions fehlen
			$data = array();
			// Open Matches Notification
			$sql="Select m.MatchID, md.Submitted, (
													SELECT COUNT(mdcmv.SteamID) as CountCancelSubmitts
													FROM MatchDetailsCancelMatchVotes mdcmv
													WHERE SteamID = ".secureNumber($steamID)." AND mdcmv.MatchID = m.MatchID
													) as CountCancelSubmitts
					FROM `MatchDetails` md JOIN `Match` m ON md.MatchID = m.MatchID
					
					WHERE md.SteamID = ".secureNumber($steamID)." AND Submitted = 0
					";
			$ret['debug'] .= $sql;
			$data = $DB->multiSelect($sql);
			
			if(is_array($data) && count($data) > 0){
				$subCount=0;
							foreach($data as $k => $v){
									if($v['Submitted'] == 0 && $v['CountCancelSubmitts'] == 0){
										$subCount++;
									}
							}
							if($subCount>0){
								$tmpData['count'] = $subCount;
								$matchString = ($count > 1 ? 'Match-Results' : 'Match-Result');
								$is = ($subCount > 1 ? 'are' : 'is');
								$tmpData['message'] = $matchString." of you ".$is." missing!";
								$tmpData['href'] = "openMatches.php?openSubmissions=true";
								$retData[] = $tmpData;
								$globalCount++;
							}
						}
			
			
			$ret['data'] = $retData;
			$ret['count'] = $globalCount;
			$ret['status'] = true;
		}
		else{
			$ret['status'] = "SteamID 0";
		}
		
		return $ret;
	}

}

?>